package com.theory.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.theory.pojo.R;
import com.theory.pojo.Subject;
import com.theory.service.SubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/subject")
public class SubjectController {

    @Resource
    private SubjectService subjectService;


    @GetMapping("/import")
    public void batchImport() {
        String fileName = "1.xlsx";
        subjectService.importData(fileName);
    }


    @GetMapping("listPage/{page}/{limit}/{str}")
    public R listPage(@PathVariable Long page, @PathVariable Long limit, @PathVariable String str) {
        Page<Subject> pageParam = new Page<>(page, limit);
        IPage<Subject> pageModel =  subjectService.listPage(pageParam, str);
        return R.ok().data("pageModel", pageModel);
    }

}

